package org.threebitsoftware.tbb.dao;

import java.sql.SQLException;
import java.util.Vector;

import org.apache.log4j.Logger;
import org.threebitsoftware.dao.generated.ContactKey;
import org.threebitsoftware.dao.generated.EmailaddressKey;
import org.threebitsoftware.dao.generated.orm.ContactDAOImpl;

import com.pew.util.dao.DatabaseConection;
import com.pew.util.dao.DatabaseUtil;

import com.pew.util.dao.DatabaseUtil;

public class Contact implements DeletableDomainObjectInterface {

	private static Logger cLogger = Logger.getLogger(Contact.class);
	
	String cStrFirstName = "";
	String cStrLastName = "";
	String cStrMiddleName = "";
	String cStrSuffix = "";
	String cStrPrefix = "";
	String cStrCompany = "";
	String cStrTitle = "";
	int iIsPerson = 1;
	
	org.threebitsoftware.dao.generated.Contact cDAOContact = new org.threebitsoftware.dao.generated.Contact();
	ContactDAOImpl cContactDAOImpl = new ContactDAOImpl();
	
	Vector<String> cVectorTags = new Vector();
	Vector<Address> cVectorAddress = new Vector();
	Vector<EmailAddress> cVectorEmail = new Vector();
	Vector<PhoneNumber> cVectorPhoneNumber = new Vector();
	
	
	private byte[] photo;
	
	int iIdContact = -1;
	int iIdAppUser = -1;
	
	boolean markedForDeletion = false;

	
	public Contact() {
		cLogger.debug("Contact initialized");
	}

	public Contact(String strFirstName, String strLastName,
			String strMiddleName, String strSuffix, String strPrefix,
			String strCompany, String strTitle, boolean isPerson) {
		super();
		cStrFirstName = strFirstName;
		cStrLastName = strLastName;
		cStrMiddleName = strMiddleName;
		cStrSuffix = strSuffix;
		cStrPrefix = strPrefix;
		cStrCompany = strCompany;
		cStrTitle = strTitle;
		iIsPerson = (isPerson?1:0);
	}
	
	/*
	 * Auxilary methods.
	 */

	public void addPhoneNumber(String myStrPhoneNumber, String myStrDescription)
	{
		PhoneNumber lPhoneNumber = new PhoneNumber(myStrPhoneNumber, myStrDescription);
		cVectorPhoneNumber.add(lPhoneNumber);
		cLogger.debug("Added phone number to contact:" + lPhoneNumber.toString());
	}
	
	public void addPhoneNumber(PhoneNumber myPhoneNumber)
	{
		cVectorPhoneNumber.add(myPhoneNumber);
		cLogger.debug("Added phone number to contact:" + myPhoneNumber.toString());
	}
	
	public void addEmailAddress(String myStrEmail, String myStrDesription)
	{
		EmailAddress lEmailAddress = new EmailAddress(myStrEmail, myStrDesription);
		cVectorEmail.add(lEmailAddress);
		cLogger.debug("Added email address to contact:" + lEmailAddress.toString());
	}
	
	public void addEmailAddress(EmailAddress myEmail)
	{
		cVectorEmail.add(myEmail);
		cLogger.debug("Added email address to contact:" + myEmail.toString());
	}
	
	
	public void addAddress(Address myAddress)
	{
		cVectorAddress.add(myAddress);
		cLogger.debug("Added address: " + myAddress.toString());
	}

	/*
	 * Getters and Setters
	 */

	/**
	 * @return the cStrFirstName
	 */
	public String getFirstName() {
		return cStrFirstName;
	}

	/**
	 * @param strFirstName the cStrFirstName to set
	 */
	public void setFirstName(String strFirstName) {
		cStrFirstName = strFirstName;
	}

	/**
	 * @return the cStrLastName
	 */
	public String getLastName() {
		return cStrLastName;
	}

	/**
	 * @param strLastName the cStrLastName to set
	 */
	public void setLastName(String strLastName) {
		cStrLastName = strLastName;
	}

	/**
	 * @return the cStrMiddleName
	 */
	public String getMiddleName() {
		return cStrMiddleName;
	}

	/**
	 * @param strMiddleName the cStrMiddleName to set
	 */
	public void setMiddleName(String strMiddleName) {
		cStrMiddleName = strMiddleName;
	}

	/**
	 * @return the cStrSuffix
	 */
	public String getSuffix() {
		return cStrSuffix;
	}

	/**
	 * @param strSuffix the cStrSuffix to set
	 */
	public void setSuffix(String strSuffix) {
		cStrSuffix = strSuffix;
	}

	/**
	 * @return the cStrPrefix
	 */
	public String getPrefix() {
		return cStrPrefix;
	}

	/**
	 * @param strPrefix the cStrPrefix to set
	 */
	public void setPrefix(String strPrefix) {
		cStrPrefix = strPrefix;
	}

	/**
	 * @return the cStrCompany
	 */
	public String getCompany() {
		return cStrCompany;
	}

	/**
	 * @param strCompany the cStrCompany to set
	 */
	public void setCompany(String strCompany) {
		cStrCompany = strCompany;
	}

	/**
	 * @return the cStrTitle
	 */
	public String getTitle() {
		return cStrTitle;
	}

	/**
	 * @param strTitle the cStrTitle to set
	 */
	public void setTitle(String strTitle) {
		cStrTitle = strTitle;
	}

	/**
	 * @return the iIsPerson
	 */
	public boolean isPerson() {
		return (iIsPerson == 0?false:true);
	}

	/**
	 * @param isPerson the iIsPerson to set
	 */
	public void setIsPerson(boolean isPerson) {
		if (isPerson) {
			iIsPerson = 1;
		}
		else
		{
			iIsPerson = 0;
		}
	}

	/**
	 * @return the cVectorAddress
	 */
	public Vector<Address> getAddresses() {
		return cVectorAddress;
	}

	/**
	 * @param vectorAddress the cVectorAddress to set
	 */
	public void setAddresses(Vector<Address> vectorAddress) {
		cVectorAddress = vectorAddress;
	}

	/**
	 * @return the cVectorEmail
	 */
	public Vector<EmailAddress> getEmails() {
		return cVectorEmail;
	}

	/**
	 * @param vectorEmail the cVectorEmail to set
	 */
	public void setEmails(Vector<EmailAddress> vectorEmail) {
		cVectorEmail = vectorEmail;
	}

	/**
	 * @return the cVectorPhoneNumer
	 */
	public Vector<PhoneNumber> getPhoneNumbers() {
		return cVectorPhoneNumber;
	}

	/**
	 * @param vectorPhoneNumer the cVectorPhoneNumer to set
	 */
	public void setPhoneNumbers(Vector<PhoneNumber> vectorPhoneNumber) {
		cVectorPhoneNumber = vectorPhoneNumber;
	}

	/**
	 * @return the cVectorTags
	 */
	public Vector<String> getTags() {
		return cVectorTags;
	}

	/**
	 * @param vectorTags the cVectorTags to set
	 */
	public void setTags(Vector vectorTags) {
		cVectorTags = vectorTags;
	}

	/**
	 * 
	 * @return byte[]
	 */
	public byte[] getPhoto() {
		return photo;
	}

	/**
	 * 
	 * @param photo
	 */
	public void setPhoto(byte[] photo) {
		this.photo = photo;
	}

	/**
	 * @return the iIdContact
	 */
	public int getIdContact() {
		return iIdContact;
	}

	/**
	 * @param idContact the iIdContact to set
	 */
	public void setIdContact(int idContact) {
		iIdContact = idContact;
	}

	/**
	 * @return the iIdAppUser
	 */
	public int getIdAppUser() {
		return iIdAppUser;
	}

	/**
	 * @param idAppUser the iIdAppUser to set
	 */
	public void setIdAppUser(int idAppUser) {
		iIdAppUser = idAppUser;
	}
	
	public void markForDeletion(boolean deleteMe)
	{
		markedForDeletion = deleteMe;
	}
	
	public boolean isMarkedForDeletion()
	{
		return markedForDeletion;
	}
	
	
}
